from common.Utils import SHPDriver
from selenium.webdriver.common.by import By
import ddddocr
import time
#商城系统注册页面
class Register:
    def __init__(self):
        self.url="http://49.235.61.184/?s=user/regInfo.html"
        self.driver=SHPDriver.driver
        self.driver.get(self.url)

    def captcha(self):
        ele = self.driver.find_element(By.XPATH, '//*[@id="form-verify-img"]')
        ele.screenshot('code.png')
        ele_bytes = ele.screenshot_as_png
        ocr = ddddocr.DdddOcr(show_ad=False)  # 关闭广告输出
        text = ocr.classification(ele_bytes)
        self.driver.find_element(By.XPATH, '//*[@type="text" and @name="verify"]').send_keys(text)
    #什么都不点直接注册
    def RegisterTest0(self):
        self.driver.find_element(By.XPATH,
                                 "/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[5]/button").click()  # 点击“注册”按钮
        time.sleep(2.5)
        SHPDriver.GetScreenShot()
    #用户已存在
    def RegisterTest1(self):
        self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").send_keys("zzz111")  # 输入“已存在的用户名”
        self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").send_keys("zzz123")  # 输入密码
        self.captcha()  # 自动识别并填入验证码
        self.driver.find_element(By.XPATH, "//*[@class=\"am-icon-checked\"]").click()  # 勾选“同意协议”
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[5]/button").click()  # 点击“注册”按钮
        time.sleep(2.5)
        #self.driver.implicitly_wait(5)
        SHPDriver.GetScreenShot()
    # 注册成功
    def RegisterTest2(self):
        self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").clear()  # 清空已有用户名
        self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").clear()  # 清空已有密码
        self.driver.find_element(By.XPATH, "//*[@name=\"accounts\"]").send_keys("lala")  # 输入“新用户名”
        self.driver.find_element(By.XPATH, "//*[@name=\"pwd\"]").send_keys("123456")  # 输入密码
        self.captcha()  # 自动识别并填入验证码
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[3]/div/div/div[2]/div/div[1]/div[1]/form/div[5]/button").click()  # 点击“注册”按钮
        time.sleep(2.5)
        #self.driver.implicitly_wait(5)
        SHPDriver.GetScreenShot()
Test=Register()
Test.RegisterTest0()  # 调用“什么都不点直接注册”测试
Test.RegisterTest1()  # 调用了“用户已存在”测试
Test.RegisterTest2()  # 调用了“注册成功”测试
